package dyy.zc.alumnibook.ui.activity;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

import dyy.zc.alumnibook.R;
import dyy.zc.alumnibook.base.BaseActivity;
import dyy.zc.alumnibook.bean.UserInfo;
import dyy.zc.alumnibook.utils.BmobUtils;
import dyy.zc.alumnibook.utils.ImageLoaderUtils;
import dyy.zc.alumnibook.views.CircleImageView;

public class ShowFriendInfoActivity extends BaseActivity {
    private TextView tvName, tvSex, tvBirth, tvAge;
    private TextView tvConstellation, tvCompany, tvSchool, tvHomeTown, tvMailBox;
    private TextView title;
    private CircleImageView head;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 1:
                    Bundle bundle = msg.getData();
                    UserInfo userInfo = (UserInfo) bundle.getSerializable("info");
                    setInfo(userInfo);
                    dialog.dismiss();
                    break;
            }
        }
    };

    private void setInfo(UserInfo userInfo) {
        ImageLoaderUtils.initImage(this, userInfo.getHead().getFileUrl(), head, R.drawable.chat_xe_icon2_03);
        tvName.setText(userInfo.getName());
        tvSex.setText(userInfo.getSex());
        tvBirth.setText(userInfo.getBirthday());
        tvAge.setText(userInfo.getAge());
        tvConstellation.setText(userInfo.getConstellation());
        tvCompany.setText(userInfo.getCompany());
        tvSchool.setText(userInfo.getSchool());
        tvHomeTown.setText(userInfo.getHometown());
        tvMailBox.setText(userInfo.getEmail());
    }

    @Override
    protected void findViewByIDS() {
        head = (CircleImageView) findViewById(R.id.edit_myinfo_civ_head);
        tvName = (TextView) findViewById(R.id.tv_info_name);
        tvSex = (TextView) findViewById(R.id.tv_info_sex);
        tvBirth = (TextView) findViewById(R.id.tv_info_birth);
        tvAge = (TextView) findViewById(R.id.tv_info_age);
        tvConstellation = (TextView) findViewById(R.id.tv_info_constellation);
        tvCompany = (TextView) findViewById(R.id.tv_info_company);
        tvSchool = (TextView) findViewById(R.id.tv_info_school);
        tvHomeTown = (TextView) findViewById(R.id.tv_hometown);
        tvMailBox = (TextView) findViewById(R.id.tv_info_mailbox);

        title = (TextView) findViewById(R.id.top_tv_title);
        title.setText("个人信息");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_friend_info);
        initData();
    }

    private void initData() {
        dialog = ProgressDialog.show(this, null, "正在获取信息....");
        BmobUtils bmobUtils = new BmobUtils(this);
        Intent intent = getIntent();
        String id = intent.getStringExtra("id");
        bmobUtils.getFriendInfo(id, 1, handler);
    }
}
